/*
 * Copyright 2010 Chad Retz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jdocng.shared.model;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlType;

import com.google.common.annotations.GwtCompatible;
import com.google.gson.annotations.Expose;
import com.sun.javadoc.Doc;

/**
 * Implementation of {@link Doc}
 *
 * @author Chad Retz
 */
@XmlType(name = "doc")
@GwtCompatible(serializable = true)
@SuppressWarnings("serial")
public abstract class DocImpl extends JavadocNgEntity implements Doc {

    //exposed fields
    
    @Expose
    private String commentText;

    @Expose
    private TagImpl[] firstSentenceTags;

    @Expose
    private String rawCommentText;

    @Expose
    private TagImpl[] inlineTags;

    @Expose
    private boolean annotationType;

    @Expose
    private boolean annotationTypeElement;

    @Expose
    private boolean classInstance;

    @Expose
    private boolean constructor;

    @Expose
    private boolean enumInstance;

    @Expose
    private boolean enumConstant;

    @Expose
    private boolean error;

    @Expose
    private boolean exception;

    @Expose
    private boolean field;

    @Expose
    private boolean included;

    @Expose
    private boolean interfaceInstance;

    @Expose
    private boolean method;

    @Expose
    private boolean ordinaryClass;

    @Expose
    private String name;

    @Expose
    private SourcePositionImpl position;

    @Expose
    private SeeTagImpl[] seeTags;

    @Expose
    private TagImpl[] tags;
    
    //Doc interface impl
    
    @Override
    public String commentText() {
        return commentText;
    }
    
    @Override
    public int compareTo(Object object) {
        if (object instanceof DocImpl) {
            return name.compareTo(((DocImpl) object).name);
        } else {
            return -1;
        }
    }
    
    @Override
    public TagImpl[] firstSentenceTags() {
        return firstSentenceTags;
    }
    
    @Override
    public String getRawCommentText() {
        return rawCommentText;
    }
    
    @Override
    public TagImpl[] inlineTags() {
        return inlineTags;
    }
    
    @Override
    public boolean isAnnotationType() {
        return annotationType;
    }
    
    @Override
    public boolean isAnnotationTypeElement() {
        return annotationTypeElement;
    }
    
    @Override
    public boolean isClass() {
        return classInstance;
    }
    
    @Override
    public boolean isConstructor() {
        return constructor;
    }
    
    @Override
    public boolean isEnum() {
        return enumInstance;
    }
    
    @Override
    public boolean isEnumConstant() {
        return enumConstant;
    }
    
    @Override
    public boolean isError() {
        return error;
    }
    
    @Override
    public boolean isException() {
        return exception;
    }
    
    @Override
    public boolean isField() {
        return field;
    }
    
    @Override
    public boolean isIncluded() {
        return included;
    }
    
    @Override
    public boolean isInterface() {
        return interfaceInstance;
    }
    
    @Override
    public boolean isMethod() {
        return method;
    }
    
    @Override
    public boolean isOrdinaryClass() {
        return ordinaryClass;
    }
    
    @Override
    public String name() {
        return name;
    }
    
    @Override
    public SourcePositionImpl position() {
        return position;
    }
    
    @Override
    public SeeTagImpl[] seeTags() {
        return seeTags;
    }
    
    @Override
    public void setRawCommentText(String rawCommentText) {
        this.rawCommentText = rawCommentText;
    }
    
    @Override
    public TagImpl[] tags() {
        return tags;
    }
    
    @Override
    public TagImpl[] tags(String tagname) {
        List<TagImpl> ret = new ArrayList<TagImpl>(tags.length);
        for (TagImpl tag : tags) {
            if (tagname.equals(tag.kind())) {
                ret.add(tag);
            }
        }
        return ret.toArray(new TagImpl[0]);
    }

    //other accessors
    
    public void setCommentText(String commentText) {
        this.commentText = commentText;
    }
    
    public void setFirstSentenceTags(TagImpl[] firstSentenceTags) {
        this.firstSentenceTags = firstSentenceTags;
    }
    
    public void setInlineTags(TagImpl[] inlineTags) {
        this.inlineTags = inlineTags;
    }
    
    public void setAnnotationType(boolean annotationType) {
        this.annotationType = annotationType;
    }
    
    public void setAnnotationTypeElement(boolean annotationTypeElement) {
        this.annotationTypeElement = annotationTypeElement;
    }
    
    public void setClassInstance(boolean classInstance) {
        this.classInstance = classInstance;
    }
    
    public void setConstructor(boolean constructor) {
        this.constructor = constructor;
    }
    
    public void setEnumInstance(boolean enumInstance) {
        this.enumInstance = enumInstance;
    }
    
    public void setEnumConstant(boolean enumConstant) {
        this.enumConstant = enumConstant;
    }
    
    public void setError(boolean error) {
        this.error = error;
    }
    
    public void setException(boolean exception) {
        this.exception = exception;
    }
    
    public void setField(boolean field) {
        this.field = field;
    }
    
    public void setIncluded(boolean included) {
        this.included = included;
    }
    
    public void setInterfaceInstance(boolean interfaceInstance) {
        this.interfaceInstance = interfaceInstance;
    }
    
    public void setMethod(boolean method) {
        this.method = method;
    }
    
    public void setOrdinaryClass(boolean ordinaryClass) {
        this.ordinaryClass = ordinaryClass;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public void setPosition(SourcePositionImpl position) {
        this.position = position;
    }
    
    public void setSeeTags(SeeTagImpl[] seeTags) {
        this.seeTags = seeTags;
    }
    
    public void setTags(TagImpl[] tags) {
        this.tags = tags;
    }
        
}
